Working with Background Properties

The background properties serve the purpose of setting the background styles of HTML elements. You can use the background properties to enhance the background styles of the elements present in your HTML web page.

Below given lists the available background properties:

Property

Description

background

Works as a shorthand property for all background properties such as background-color, background-image, background-repeat, background-attachment, and background-position properties it sets all these background properties in one declaration.

background-attachment

Specifies whether a background image is fixed or scrolls when the user scrolls the rest of the page. You can set this property to either scroll or fixed.

background-color

Specifies the background color of an element. You can set this property to a predefined color name, color value, or transparent.

background-image

Specifies the background image of an element. You can set this property to none or the Web address (or URL) of an image.

background-position

Specifies the initial position of a background image. You can set this property to left/center/right top, center  left/center/right, left/center/right  bottom, x% y%, x-position  y-position.

background-repeat

Specifies whether the background image is repeated or not. You can set this property to repeat, repeat-x, repeat-y, or no-repeat.

Let’s now learn how to set the background color and image with the background properties on an HTML Web Page.